package com.example.demo.springboot_demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.demo.springboot_demo.entity.User;
import com.example.demo.springboot_demo.mapper.UserMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hua
 * @since 2024-09-03
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserMapper userMapper;

    @RequestMapping("/insert")
    public void insertUser(@RequestBody User user){
        userMapper.insert(user);
    }
    @RequestMapping("/del")
    public void delUserById(int uid){
        userMapper.deleteById(uid);
    }
    @RequestMapping("/del2")
    public void delUser(@RequestParam("username")String uname,@RequestParam("userPassword")String upwd){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("uname",uname).eq("upwd",upwd);
        userMapper.delete(wrapper);
    }
    @RequestMapping("/update")
    public void updateUser(@RequestBody User user){
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("uid",user.getUid());
        userMapper.update(user,wrapper);
    }
    @RequestMapping("/selectAll")
    public List<User> selectAll(){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
//        wrapper.eq("uid","");
        return userMapper.selectList(wrapper);
    }

}

